package com.hc.springboot;

import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringbootFileUploadApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringbootFileUploadApplication.class, args);
	}
	
	//为了解决，上传文件大于10M出现连接重置的问题。此异常内容GlobalException也捕获不到
	//tomcat large file upload connection reset
	@Bean
	public TomcatServletWebServerFactory webServerFactory() {
		TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
		tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
			if((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)){
				//-1 means unlimited
				((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
			}
		});
		return tomcat;
	}
}
